 
#ifndef __THREAD_H__ 
#define __THREAD_H__ 
 
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <pthread.h>

using namespace std;
enum {
    THREAD_START = 0,
    THREAD_RUNNING,
    THREAD_STOP,
    THREAD_EXIT,
    THREAD_END
};
 
class threadBase{
    public:
        threadBase(){
 
        };
        int state = THREAD_START;
        virtual bool threadLoop() = 0;
        void run();
        void threadRerun();
        void threadStop();
        void threadExit();
        bool threadIsExit();
        bool threadIsStop();
    private:
        
        pthread_t tid;
        pthread_attr_t attr;
 
        pthread_mutex_t mutex  = PTHREAD_MUTEX_INITIALIZER; //定义互斥锁
        pthread_cond_t cond = PTHREAD_COND_INITIALIZER; //定义条件变量
        
    
        virtual void readyToRun();
        virtual void readyToEnd();
 
        static void *threadFun(void *arg);
        void threadEnd();
        
        void sendCond();
        void waitCond();
};
 
 
 
 
#endif /*__THREAD_H__*/